package com.ln.cmsln.controller.wei;

import com.ln.cmsln.pojo.entity.wei.Suspension;
import com.ln.cmsln.service.wei.SuspensionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 魏存文
 * @since 2022-03-31
 */

@Api(tags = "首页悬浮框")
@RestController
@RequestMapping("/api/suspension")
@CrossOrigin
public class SuspensionController {
    @Resource
    private SuspensionService suspensionService;

    @ApiOperation("首页悬浮框数据")
    @GetMapping("/list")
    public Object list(){
        List<Suspension> list = suspensionService.list();
        HashMap<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("message", "请求数据成功");
        map.put("data", list);
        return map;
    }

    @ApiOperation("新增悬浮框数据")
    @PostMapping("/save")
    public boolean save(
            @ApiParam(value = "悬浮框数据",required = true)
            Suspension suspension
    ){
        return suspensionService.save(suspension);
    }

    @ApiOperation("删除悬浮框数据")
    @PostMapping("/delete")
    public boolean deleteById(
            @ApiParam(value = "悬浮框数id") Long id
    ){
        return suspensionService.removeById(id);
    }
}

